import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
import { Student } from './student.entity';
import { CreateStudentInput } from './student.input';
import { StudentService } from './student.service';
import { StudentType } from './student.type';

@Resolver((of) => StudentType)
export class StudentResolver {
  constructor(private readonly studentServer: StudentService) {}

  @Mutation((returns) => StudentType)
  createStudent(
    @Args('createStudentInput') createStudentInput: CreateStudentInput,
  ): Promise<Student> {
    return this.studentServer.createStudent(createStudentInput);
  }

  @Query((returns) => [StudentType])
  getAllStudent(): Promise<Student[]> {
    return this.studentServer.getAllStudent();
  }

  // @Query((returns) => [StudentType])
  // 这个参数是读不到的
  // getStudentByIds(@Args('ids') ids: string[]): Promise<Student[]> {
  //   return this.studentServer.getManyStudents(ids);
  // }

  @Query((returns) => StudentType)
  getStudent(@Args('id') id: string) {
    return this.studentServer.getStudentById(id);
  }
}
